package com.yfqy.admin.resource;

import com.github.pagehelper.PageInfo;
import com.yfqy.admin.domain.dto.QueryById;
import com.yfqy.admin.domain.dto.brand.AddBrand;
import com.yfqy.admin.domain.dto.brand.BrandDetail;
import com.yfqy.admin.domain.dto.brand.BrandQuery;
import com.yfqy.admin.domain.dto.brand.ModifyBrand;
import com.yfqy.admin.service.BrandService;
import com.yfqy.admin.domain.vo.common.ResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 品牌管理
 */
@RestController
@RequestMapping("/api/internal/brand")
public class BrandController {

    private static final Logger LOGGER = LoggerFactory.getLogger(BrandController.class);

    private final BrandService brandService;

    public BrandController(BrandService brandService) {
        this.brandService = brandService;
    }

    /**
     * 品牌详情
     *
     * @param queryById
     * @return
     */
    @PostMapping({"/selectById"})
    public ResultVO<BrandDetail> selectById(@RequestBody @Validated QueryById queryById) {
        return brandService.selectById(queryById.getId());
    }

    /**
     * 品牌分页列表
     *
     * @param brandQuery
     * @return
     */
    @PostMapping("/brandPageList")
    public ResultVO<PageInfo<BrandDetail>> brandPageList(@RequestBody BrandQuery brandQuery) {
        return brandService.brandPageList(brandQuery);
    }

    /**
     * 添加品牌
     *
     * @param addBrand
     * @return
     */
    @PostMapping("/addBrand")
    public ResultVO<Long> addBrand(@RequestBody @Validated AddBrand addBrand) {
        return brandService.addBrand(addBrand);
    }


    /**
     * 修改品牌
     *
     * @param modifyBrand
     * @return
     */
    @PostMapping("/modifyBrand")
    public ResultVO<Void> modifyBrand(@RequestBody @Validated ModifyBrand modifyBrand) {
        return brandService.modifyBrand(modifyBrand);
    }


}
